<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        #app {
            padding: 10px;
        }

        .title {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .title input {
            width: 250px;
            height: 40px;
            padding-left: 10px;
            outline: none;
            border: 1px solid #ccc;
            border-radius: 10px;
        }

        .title button {
            border-radius: 10px;
            width: 80px;
            height: 35px;
            border: none;
            cursor: pointer;
            background-color: lightgreen;
            color: white;
        }

        .item {
            color: white;
            padding: 0 20px;
            line-height: 50px;
            margin: 20px 0;
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: lightcoral;
        }

        .empty {
            line-height: 40px;
            margin: 50px 0;
            text-align: center;
            color: red;
        }

        .active {
            background-color: lightgreen;
        }

        .box2 {
            color: white;
            margin-top: 10px;
            display: flex;
        }

        .box2 div {
            border-radius: 10px;
            background-color: lightgreen;
            width: 90px;
            height: 35px;
            line-height: 35px;
            text-align: center;
            margin-left: 10px;
        }

        .box2 div:last-child {
            background-color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="title">
            <input type="text" placeholder="请输入任务名称" v-model="inputText">
            <button v-on:click="add">添加</button>
        </div>
        <div class="box2">
            <div>全部任务{{list.length}}</div>
            <div>已完成({{total1()}})</div>
            <div>未完成 ({{total()}})</div>
        </div>
        <div class="task">
            <div v-bind:class=" `item ${item.status == true ? 'active' : ''}` " v-for="(item,index) in list"
                v-bind:key="index">
                <div class="left">
                    <input type="checkbox" v-on:click="changeStatus(item)">
                </div>
                <div class="name">{{ item.name }}</div>
                <div class="right" v-on:click="delet(item)">删除</div>
            </div>
            <div class="empty" v-show="list.length == 0">任务列表空空如也!!!</div>
        </div>
    </div>
    <script src="./vue-2.5.21.js"></script>
    <script>
        let v = new Vue({
            el: '#app',
            data: {
                inputText: '',
                list: []
            },
            methods: {
                add() {
                    let obj = { id: this.list.length + 1, name: this.inputText, status: false }
                    this.list.push(obj)
                    this.inputText = ''

                },
                changeStatus(item) {
                    item.status = !item.status
                },
                delet(item) {
                    let i = this.list.indexOf(item)
                    console.log(i)
                    this.list.splice(i, 1)
                },
                total() {
                    let a = this.list.filter(item => {
                        return item.status == false
                    })
                    return a.length
                },
                total1() {
                    let a = this.list.filter(item => {
                        return item.status == true
                    })
                    return a.length
                }
            },
        })
    </script>
</body>

</html>